#define _CRT_SECURE_NO_WARNINGS 1


#include<vector>
#include<algorithm>
#include<iostream>

using namespace std;

int findLHS(vector<int>& nums)
{
    sort(nums.begin(), nums.end());
    int ret = 0;
    int begin = 0, end = 0;
    int size = nums.size();
    while (end < size)
    {
        while (nums[end] - nums[begin] > 1)
        {
            begin++;
        }
        if (nums[end] - nums[begin] == 1)
        {
            ret = max(ret, end - begin + 1);
        }
        end++;
    }
    return ret;
}